package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.mapper.RoleMapper;
import com.jt.pojo.Role;
import com.jt.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImp  implements RoleService {

    @Autowired
    private RoleMapper  roleMapper;

    @Override
    public PageResult<Role> getList(PageResult<Role> rolePageResult) {
        QueryWrapper<Role>  queryWrapper=new QueryWrapper<>();
        Page<Role>  page=new Page<>();
        page.setCurrent(rolePageResult.getPageNum());
        page.setSize(rolePageResult.getPageSize());
        Page<Role> rolePage = roleMapper.selectPage(page, null);
        rolePageResult.setTotal(rolePage.getTotal());
        rolePageResult.setRows(rolePage.getRecords());
        rolePage.setRecords(page.getRecords());
        List<Role> records = rolePage.getRecords();
        for (Role record : records) {
            System.out.println(record);
        }
        return rolePageResult;
    }

    //获取所有的角色的列表
    @Override
    public List<Role> getRoleList() {
        QueryWrapper  queryWrapper=new QueryWrapper();
        queryWrapper.select("role_id","role_name");
       return  roleMapper.selectList(queryWrapper);
    }

}
